/*
 * Created by JFormDesigner on Fri Feb 19 16:47:12 CST 2016
 */

package edu.vt.cbil.ui;


import edu.vt.cbil.core.Controller;
import edu.vt.cbil.dataset.AnnotationDataSet;
import edu.vt.cbil.saic.DetectSCAs;
import edu.vt.cbil.util.ConfigObject;
import edu.vt.cbil.util.DataConversion;
import edu.vt.cbil.util.SaicParameters;

import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.IOException;
import java.util.concurrent.ForkJoinPool;
import javax.swing.*;
import javax.swing.GroupLayout;
import javax.swing.border.*;
import javax.swing.filechooser.FileFilter;
import javax.swing.filechooser.FileNameExtensionFilter;


/**
 * @author JFormDesigner 5.2.2.2
 */
public class AisaicGui extends JFrame {

    SwingAISAIC mySwingAISAIC;
    SwingSCAs mySwingSCAs;
    SwingBacom mySwingBacom;

    boolean bacomOnly = false;
    boolean saicOnly = false;
    boolean bacomAndsaic = false;

    File currentDir;

    public AisaicGui() {
        initComponents();
    }

    private void jButtonStartActionPerformed(ActionEvent e) {
        // TODO add your code here
        if(bacomOnly){
            mySwingBacom = new SwingBacom();
            mySwingBacom.execute();
        }
        else if(saicOnly){
            mySwingSCAs = new SwingSCAs();
            mySwingSCAs.execute();
        }
        else if(bacomAndsaic){
            mySwingAISAIC = new SwingAISAIC();
            mySwingAISAIC.execute();
        }
    }

    private void jRadioButtonBacomOnlyActionPerformed(ActionEvent e) {
        // TODO add your code here
        bacomOnly = jRadioButtonBacomOnly.isSelected();
        if(bacomOnly){
            saicOnly = false;
            bacomAndsaic = false;
        }
    }

    private void jRadioButtonSaicOnlyActionPerformed(ActionEvent e) {
        // TODO add your code here
        saicOnly = jRadioButtonSaicOnly.isSelected();
        if(saicOnly){
            bacomOnly = false;
            bacomAndsaic = false;
        }
    }

    private void jRadioButtonBacomSaicActionPerformed(ActionEvent e) {
        // TODO add your code here
        bacomAndsaic = jRadioButtonBacomSaic.isSelected();
        if(bacomAndsaic){
            bacomOnly = false;
            saicOnly = false;
        }
    }

    private void jButtonStopActionPerformed(ActionEvent e) {
        // TODO add your code here
        jTextAreaStatus.append("User cancelled the analysis, please allow a little while for the program to terminate all the  executing threads... " + "\n" + "\n");
        if(bacomOnly){
            mySwingBacom.cancel(true);
        }
        if(saicOnly){
            mySwingSCAs.cancel(true);
        }
        if(bacomAndsaic){
            mySwingAISAIC.cancel(true);
        }
    }

    private void jButtonChooseAnnotFileActionPerformed(ActionEvent e) {
        // TODO add your code here
        JFileChooser jFileChooser = new JFileChooser();

        FileFilter fileFilter = new FileNameExtensionFilter("db File", "db");

        jFileChooser.setFileFilter(fileFilter);

        jFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

        jFileChooser.setCurrentDirectory(currentDir);

        int returnVal = jFileChooser.showOpenDialog(getContentPane());

        if (returnVal == jFileChooser.APPROVE_OPTION)
        {
            File selectedFile = jFileChooser.getSelectedFile();
            currentDir = jFileChooser.getCurrentDirectory();
            jTextFieldAnnotFilePath.setText(selectedFile.getPath());
        }
        else
            jTextAreaStatus.append("File access cancelled by user." + "\n"+ "\n");
    }

    private void jButtonParamSettingActionPerformed(ActionEvent e) {
        // TODO add your code here
    }

    private void buttonParamSettingActionPerformed(ActionEvent e) {
        // TODO add your code here
    }

    private void jButtonChooseCdfFileActionPerformed(ActionEvent e) {
        // TODO add your code here
        JFileChooser jFileChooser = new JFileChooser();

        FileFilter fileFilter = new FileNameExtensionFilter("cdf File", "cdf");

        jFileChooser.setFileFilter(fileFilter);

        jFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

        jFileChooser.setCurrentDirectory(currentDir);

        int returnVal = jFileChooser.showOpenDialog(getContentPane());

        if (returnVal == jFileChooser.APPROVE_OPTION)
        {
            File selectedFile = jFileChooser.getSelectedFile();
            currentDir = jFileChooser.getCurrentDirectory();
            jTextFieldAnnotFilePath.setText(selectedFile.getPath());
        }
        else
            jTextAreaStatus.append("File access cancelled by user." + "\n"+ "\n");
    }

    private void jMenuItemExitActionPerformed(ActionEvent e) {
        // TODO add your code here
        System.exit(-1);
    }

    private void jButtonChooseBacomResultFolderActionPerformed(ActionEvent e) {
        // TODO add your code here
        JFileChooser jFileChooser = new JFileChooser();
        jFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        jFileChooser.setCurrentDirectory(currentDir);
        int returnVal = jFileChooser.showOpenDialog(getContentPane());
        if (returnVal == jFileChooser.APPROVE_OPTION)
        {
            File selectedFile = jFileChooser.getSelectedFile();
            currentDir = jFileChooser.getCurrentDirectory();
            jTextFieldBacomResultFolder.setText(selectedFile.getPath());
        }
        else
            jTextAreaStatus.append("File access cancelled by user." + "\n");
    }

    private void jButtonChooseNSampleActionPerformed(ActionEvent e) {
        // TODO add your code here
        JFileChooser jFileChooser = new JFileChooser();

        FileFilter fileFilter = new FileNameExtensionFilter("cel File", "cel");

        jFileChooser.setFileFilter(fileFilter);

        jFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

        jFileChooser.setCurrentDirectory(currentDir);

        int returnVal = jFileChooser.showOpenDialog(getContentPane());

        if (returnVal == jFileChooser.APPROVE_OPTION)
        {
            File selectedFile = jFileChooser.getSelectedFile();
            currentDir = jFileChooser.getCurrentDirectory();
            jTextFieldNSample.setText(selectedFile.getPath());
        }
        else
            jTextAreaStatus.append("File access cancelled by user." + "\n"+ "\n");
    }

    private void jButtonChooseTSampleActionPerformed(ActionEvent e) {
        // TODO add your code here
        JFileChooser jFileChooser = new JFileChooser();

        FileFilter fileFilter = new FileNameExtensionFilter("cel File", "cel");

        jFileChooser.setFileFilter(fileFilter);

        jFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

        jFileChooser.setCurrentDirectory(currentDir);

        int returnVal = jFileChooser.showOpenDialog(getContentPane());

        if (returnVal == jFileChooser.APPROVE_OPTION)
        {
            File selectedFile = jFileChooser.getSelectedFile();
            currentDir = jFileChooser.getCurrentDirectory();
            jTextFieldTSample.setText(selectedFile.getPath());
        }
        else
            jTextAreaStatus.append("File access cancelled by user." + "\n"+ "\n");
    }

    private void jButtonChooseSaicInputFileActionPerformed(ActionEvent e) {
        // TODO add your code here
        JFileChooser jFileChooser = new JFileChooser();

        jFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

        jFileChooser.setCurrentDirectory(currentDir);

        int returnVal = jFileChooser.showOpenDialog(getContentPane());

        if (returnVal == jFileChooser.APPROVE_OPTION)
        {
            File selectedFile = jFileChooser.getSelectedFile();
            currentDir = jFileChooser.getCurrentDirectory();
            jTextFieldSaicInputFile.setText(selectedFile.getPath());
        }
        else
            jTextAreaStatus.append("File access cancelled by user." + "\n"+ "\n");

    }

    private void jButtonChooseSaicResultFolderActionPerformed(ActionEvent e) {
        // TODO add your code here
        JFileChooser jFileChooser = new JFileChooser();
        jFileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        jFileChooser.setCurrentDirectory(currentDir);
        int returnVal = jFileChooser.showOpenDialog(getContentPane());
        if (returnVal == jFileChooser.APPROVE_OPTION)
        {
            File selectedFile = jFileChooser.getSelectedFile();
            currentDir = jFileChooser.getCurrentDirectory();
            jTextFieldSaicResultFolder.setText(selectedFile.getPath());
        }
        else
            jTextAreaStatus.append("File access cancelled by user." + "\n");

    }

    private void jButtonChooseGeneFileActionPerformed(ActionEvent e) {
        // TODO add your code here
        JFileChooser jFileChooser = new JFileChooser();

        FileFilter fileFilter = new FileNameExtensionFilter("gene File", "gene");

        jFileChooser.setFileFilter(fileFilter);

        jFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);

        jFileChooser.setCurrentDirectory(currentDir);

        int returnVal = jFileChooser.showOpenDialog(getContentPane());

        if (returnVal == jFileChooser.APPROVE_OPTION)
        {
            File selectedFile = jFileChooser.getSelectedFile();
            currentDir = jFileChooser.getCurrentDirectory();
            jTextFieldGeneFile.setText(selectedFile.getPath());
        }
        else
            jTextAreaStatus.append("File access cancelled by user." + "\n"+ "\n");

    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        menuBar1 = new JMenuBar();
        menu1 = new JMenu();
        jMenuItemExit = new JMenuItem();
        panel1 = new JPanel();
        label1 = new JLabel();
        jTextFieldAnnotFilePath = new JTextField();
        jButtonChooseAnnotFile = new JButton();
        label2 = new JLabel();
        jTextFieldCdfFilePath = new JTextField();
        jButtonChooseCdfFile = new JButton();
        label3 = new JLabel();
        jTextFieldBacomResultFolder = new JTextField();
        jButtonChooseBacomResultFolder = new JButton();
        label4 = new JLabel();
        jTextFieldNSample = new JTextField();
        jButtonChooseNSample = new JButton();
        label5 = new JLabel();
        jTextFieldTSample = new JTextField();
        jButtonChooseTSample = new JButton();
        label6 = new JLabel();
        comboBox1 = new JComboBox<>();
        jButtonParamSetting = new JButton();
        button7 = new JButton();
        panel2 = new JPanel();
        label7 = new JLabel();
        jTextFieldSaicInputFile = new JTextField();
        jButtonChooseSaicInputFile = new JButton();
        label8 = new JLabel();
        jTextFieldSaicResultFolder = new JTextField();
        jButtonChooseSaicResultFolder = new JButton();
        label9 = new JLabel();
        jTextFieldGeneFile = new JTextField();
        jButtonChooseGeneFile = new JButton();
        button10 = new JButton();
        button11 = new JButton();
        panel3 = new JPanel();
        jTextAreaStatus = new JTextArea();
        panel4 = new JPanel();
        toolBar2 = new JToolBar();
        jButtonStart = new JButton();
        jButtonStop = new JButton();
        button15 = new JButton();
        panel5 = new JPanel();
        jRadioButtonBacomOnly = new JRadioButton();
        jRadioButtonSaicOnly = new JRadioButton();
        jRadioButtonBacomSaic = new JRadioButton();

        //======== this ========
        setVisible(true);
        Container contentPane = getContentPane();

        //======== menuBar1 ========
        {

            //======== menu1 ========
            {
                menu1.setText("File");

                //---- jMenuItemExit ----
                jMenuItemExit.setText("Exit");
                jMenuItemExit.addActionListener(e -> jMenuItemExitActionPerformed(e));
                menu1.add(jMenuItemExit);
            }
            menuBar1.add(menu1);
        }
        setJMenuBar(menuBar1);

        //======== panel1 ========
        {
            panel1.setBorder(new TitledBorder(null, "BACOM2.0", TitledBorder.LEADING, TitledBorder.DEFAULT_POSITION, null, Color.blue));

            //---- label1 ----
            label1.setText("Annotation File :");
            label1.setToolTipText("Annotation");

            //---- jButtonChooseAnnotFile ----
            jButtonChooseAnnotFile.setText("...");
            jButtonChooseAnnotFile.addActionListener(e -> jButtonChooseAnnotFileActionPerformed(e));

            //---- label2 ----
            label2.setText("SNP 6.0 CDF File:");

            //---- jButtonChooseCdfFile ----
            jButtonChooseCdfFile.setText("...");
            jButtonChooseCdfFile.addActionListener(e -> jButtonChooseCdfFileActionPerformed(e));

            //---- label3 ----
            label3.setText("Restult / Data :");

            //---- jButtonChooseBacomResultFolder ----
            jButtonChooseBacomResultFolder.setText("...");
            jButtonChooseBacomResultFolder.addActionListener(e -> jButtonChooseBacomResultFolderActionPerformed(e));

            //---- label4 ----
            label4.setText("Normal Samples:");

            //---- jButtonChooseNSample ----
            jButtonChooseNSample.setText("...");
            jButtonChooseNSample.addActionListener(e -> jButtonChooseNSampleActionPerformed(e));

            //---- label5 ----
            label5.setText("Turmor Samples:");

            //---- jButtonChooseTSample ----
            jButtonChooseTSample.setText("...");
            jButtonChooseTSample.addActionListener(e -> jButtonChooseTSampleActionPerformed(e));

            //---- label6 ----
            label6.setText("Select interesting chromosome:");

            //---- comboBox1 ----
            comboBox1.setModel(new DefaultComboBoxModel<>(new String[] {
                "Chromosome1",
                "Chromosome2",
                "Chromosome3",
                "Chromosome4",
                "Chromosome5",
                "Chromosome6",
                "Chromosome7",
                "Chromosome8",
                "Chromosome9",
                "Chromosome10",
                "Chromosome11",
                "Chromosome12",
                "Chromosome13",
                "Chromosome14",
                "Chromosome15",
                "Chromosome16",
                "Chromosome17",
                "Chromosome18",
                "Chromosome19",
                "Chromosome20",
                "Chromosome21",
                "Chromosome22",
                "All chromosomes"
            }));

            //---- jButtonParamSetting ----
            jButtonParamSetting.setText("Parameters Settings");
            jButtonParamSetting.addActionListener(e -> {
			buttonParamSettingActionPerformed(e);
			jButtonParamSettingActionPerformed(e);
		});

            //---- button7 ----
            button7.setText("Add/Remove");

            GroupLayout panel1Layout = new GroupLayout(panel1);
            panel1.setLayout(panel1Layout);
            panel1Layout.setHorizontalGroup(
                panel1Layout.createParallelGroup()
                    .addGroup(panel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(panel1Layout.createParallelGroup()
                            .addGroup(panel1Layout.createSequentialGroup()
                                .addComponent(label6, GroupLayout.PREFERRED_SIZE, 221, GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(comboBox1))
                            .addGroup(panel1Layout.createSequentialGroup()
                                .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(label5, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(label4, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(label3, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(label2, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(label1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 26, Short.MAX_VALUE)
                                .addGroup(panel1Layout.createParallelGroup()
                                    .addComponent(jTextFieldCdfFilePath, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 263, GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextFieldAnnotFilePath, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 263, GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextFieldBacomResultFolder, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 263, GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextFieldNSample, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 263, GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextFieldTSample, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 263, GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(panel1Layout.createParallelGroup()
                                    .addComponent(jButtonChooseCdfFile, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 45, GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jButtonChooseAnnotFile, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 45, GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jButtonChooseBacomResultFolder, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 45, GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jButtonChooseNSample, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 45, GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jButtonChooseTSample, GroupLayout.Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 45, GroupLayout.PREFERRED_SIZE))))
                        .addGap(18, 18, 18))
                    .addGroup(panel1Layout.createSequentialGroup()
                        .addGap(43, 43, 43)
                        .addComponent(jButtonParamSetting, GroupLayout.PREFERRED_SIZE, 171, GroupLayout.PREFERRED_SIZE)
                        .addGap(74, 74, 74)
                        .addComponent(button7)
                        .addContainerGap(77, Short.MAX_VALUE))
            );
            panel1Layout.setVerticalGroup(
                panel1Layout.createParallelGroup()
                    .addGroup(panel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(label1)
                            .addComponent(jButtonChooseAnnotFile)
                            .addComponent(jTextFieldAnnotFilePath, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(label2)
                            .addComponent(jButtonChooseCdfFile)
                            .addComponent(jTextFieldCdfFilePath, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(label3)
                            .addComponent(jButtonChooseBacomResultFolder)
                            .addComponent(jTextFieldBacomResultFolder, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(label4)
                            .addComponent(jButtonChooseNSample)
                            .addComponent(jTextFieldNSample, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(label5)
                            .addComponent(jButtonChooseTSample)
                            .addComponent(jTextFieldTSample, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panel1Layout.createParallelGroup()
                            .addComponent(label6)
                            .addComponent(comboBox1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(panel1Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(jButtonParamSetting)
                            .addComponent(button7))
                        .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
        }

        //======== panel2 ========
        {
            panel2.setBorder(new TitledBorder(null, "SAIC", TitledBorder.LEADING, TitledBorder.DEFAULT_POSITION, null, Color.blue));

            //---- label7 ----
            label7.setText("Input Segmented CNA data:");

            //---- jButtonChooseSaicInputFile ----
            jButtonChooseSaicInputFile.setText("...");
            jButtonChooseSaicInputFile.addActionListener(e -> jButtonChooseSaicInputFileActionPerformed(e));

            //---- label8 ----
            label8.setText("SAIC detection result folder:");

            //---- jButtonChooseSaicResultFolder ----
            jButtonChooseSaicResultFolder.setText("...");
            jButtonChooseSaicResultFolder.addActionListener(e -> jButtonChooseSaicResultFolderActionPerformed(e));

            //---- label9 ----
            label9.setText("Gene reference file:");

            //---- jButtonChooseGeneFile ----
            jButtonChooseGeneFile.setText("...");
            jButtonChooseGeneFile.addActionListener(e -> jButtonChooseGeneFileActionPerformed(e));

            //---- button10 ----
            button10.setText("Parameters Settings");

            //---- button11 ----
            button11.setText("Add/Remove");

            GroupLayout panel2Layout = new GroupLayout(panel2);
            panel2.setLayout(panel2Layout);
            panel2Layout.setHorizontalGroup(
                panel2Layout.createParallelGroup()
                    .addGroup(panel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(panel2Layout.createParallelGroup()
                            .addGroup(panel2Layout.createSequentialGroup()
                                .addComponent(label7, GroupLayout.PREFERRED_SIZE, 194, GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldSaicInputFile)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButtonChooseSaicInputFile, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE))
                            .addGroup(panel2Layout.createSequentialGroup()
                                .addComponent(label8, GroupLayout.PREFERRED_SIZE, 194, GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextFieldSaicResultFolder)
                                .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButtonChooseSaicResultFolder, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE))
                            .addGroup(panel2Layout.createSequentialGroup()
                                .addGroup(panel2Layout.createParallelGroup(GroupLayout.Alignment.TRAILING)
                                    .addGroup(panel2Layout.createSequentialGroup()
                                        .addComponent(label9, GroupLayout.PREFERRED_SIZE, 194, GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(jTextFieldGeneFile, GroupLayout.DEFAULT_SIZE, 228, Short.MAX_VALUE)
                                        .addGap(6, 6, 6))
                                    .addGroup(panel2Layout.createSequentialGroup()
                                        .addGap(34, 34, 34)
                                        .addComponent(button10, GroupLayout.PREFERRED_SIZE, 178, GroupLayout.PREFERRED_SIZE)
                                        .addGap(60, 60, 60)
                                        .addComponent(button11, GroupLayout.PREFERRED_SIZE, 137, GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, 25, Short.MAX_VALUE)))
                                .addComponent(jButtonChooseGeneFile, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap())
            );
            panel2Layout.setVerticalGroup(
                panel2Layout.createParallelGroup()
                    .addGroup(panel2Layout.createSequentialGroup()
                        .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(panel2Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                .addComponent(jButtonChooseSaicInputFile)
                                .addComponent(jTextFieldSaicInputFile, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                .addComponent(label7))
                        .addGap(18, 18, 18)
                        .addGroup(panel2Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                .addComponent(jTextFieldSaicResultFolder, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                                .addComponent(label8)
                                .addComponent(jButtonChooseSaicResultFolder))
                        .addGroup(panel2Layout.createParallelGroup()
                            .addGroup(panel2Layout.createSequentialGroup()
                                    .addGap(16, 16, 16)
                                    .addComponent(jButtonChooseGeneFile))
                            .addGroup(panel2Layout.createSequentialGroup()
                                    .addGap(18, 18, 18)
                                    .addGroup(panel2Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                                            .addComponent(label9)
                                            .addComponent(jTextFieldGeneFile, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))))
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panel2Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(button10)
                            .addComponent(button11)))
            );
        }

        //======== panel3 ========
        {
            panel3.setBorder(new TitledBorder(null, "Processing Status", TitledBorder.LEADING, TitledBorder.DEFAULT_POSITION, null, Color.blue));

            GroupLayout panel3Layout = new GroupLayout(panel3);
            panel3.setLayout(panel3Layout);
            panel3Layout.setHorizontalGroup(
                panel3Layout.createParallelGroup()
                    .addGroup(panel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jTextAreaStatus)
                        .addContainerGap())
            );
            panel3Layout.setVerticalGroup(
                panel3Layout.createParallelGroup()
                    .addGroup(GroupLayout.Alignment.TRAILING, panel3Layout.createSequentialGroup()
                        .addComponent(jTextAreaStatus, GroupLayout.DEFAULT_SIZE, 125, Short.MAX_VALUE)
                        .addContainerGap())
            );
        }

        //======== panel4 ========
        {
            panel4.setBorder(new TitledBorder(null, "", TitledBorder.LEADING, TitledBorder.DEFAULT_POSITION, null, Color.blue));

            //======== toolBar2 ========
            {

                //---- jButtonStart ----
                jButtonStart.setText("Start");
                jButtonStart.addActionListener(e -> jButtonStartActionPerformed(e));
                toolBar2.add(jButtonStart);

                //---- jButtonStop ----
                jButtonStop.setText("Stop");
                jButtonStop.addActionListener(e -> jButtonStopActionPerformed(e));
                toolBar2.add(jButtonStop);

                //---- button15 ----
                button15.setText("Show Result");
                toolBar2.add(button15);
            }

            GroupLayout panel4Layout = new GroupLayout(panel4);
            panel4.setLayout(panel4Layout);
            panel4Layout.setHorizontalGroup(
                panel4Layout.createParallelGroup()
                    .addGroup(panel4Layout.createSequentialGroup()
                        .addGap(133, 133, 133)
                        .addComponent(toolBar2, GroupLayout.PREFERRED_SIZE, 217, GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(141, Short.MAX_VALUE))
            );
            panel4Layout.setVerticalGroup(
                panel4Layout.createParallelGroup()
                    .addGroup(panel4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(toolBar2, GroupLayout.PREFERRED_SIZE, 46, GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(15, Short.MAX_VALUE))
            );
        }

        //======== panel5 ========
        {
            panel5.setBorder(new TitledBorder(null, "Choose Model", TitledBorder.LEADING, TitledBorder.DEFAULT_POSITION, null, Color.blue));

            //---- jRadioButtonBacomOnly ----
            jRadioButtonBacomOnly.setText("BACOM");
            jRadioButtonBacomOnly.addActionListener(e -> jRadioButtonBacomOnlyActionPerformed(e));

            //---- jRadioButtonSaicOnly ----
            jRadioButtonSaicOnly.setText("SAIC");
            jRadioButtonSaicOnly.addActionListener(e -> jRadioButtonSaicOnlyActionPerformed(e));

            //---- jRadioButtonBacomSaic ----
            jRadioButtonBacomSaic.setText("BACOM+SAIC");
            jRadioButtonBacomSaic.addActionListener(e -> jRadioButtonBacomSaicActionPerformed(e));

            GroupLayout panel5Layout = new GroupLayout(panel5);
            panel5.setLayout(panel5Layout);
            panel5Layout.setHorizontalGroup(
                panel5Layout.createParallelGroup()
                    .addGroup(panel5Layout.createSequentialGroup()
                        .addGap(35, 35, 35)
                        .addComponent(jRadioButtonBacomOnly)
                        .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jRadioButtonSaicOnly)
                        .addGap(287, 287, 287)
                        .addComponent(jRadioButtonBacomSaic)
                        .addGap(48, 48, 48))
            );
            panel5Layout.setVerticalGroup(
                panel5Layout.createParallelGroup()
                    .addGroup(GroupLayout.Alignment.TRAILING, panel5Layout.createSequentialGroup()
                        .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(panel5Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(jRadioButtonBacomSaic)
                            .addComponent(jRadioButtonBacomOnly)
                            .addComponent(jRadioButtonSaicOnly))
                        .addContainerGap())
            );
        }

        GroupLayout contentPaneLayout = new GroupLayout(contentPane);
        contentPane.setLayout(contentPaneLayout);
        contentPaneLayout.setHorizontalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(GroupLayout.Alignment.TRAILING, contentPaneLayout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.TRAILING)
                        .addComponent(panel5, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(GroupLayout.Alignment.LEADING, contentPaneLayout.createSequentialGroup()
                            .addComponent(panel1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                            .addGroup(contentPaneLayout.createParallelGroup()
                                .addComponent(panel4, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(panel2, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                        .addComponent(panel3, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addContainerGap())
        );
        contentPaneLayout.setVerticalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(panel5, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                        .addComponent(panel1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                        .addGroup(GroupLayout.Alignment.TRAILING, contentPaneLayout.createSequentialGroup()
                            .addComponent(panel2, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGap(18, 18, 18)
                            .addComponent(panel4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(panel3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .addGap(7, 7, 7))
        );
        pack();
        setLocationRelativeTo(getOwner());

        //---- buttonGroup1 ----
        ButtonGroup buttonGroup1 = new ButtonGroup();
        buttonGroup1.add(jRadioButtonBacomOnly);
        buttonGroup1.add(jRadioButtonSaicOnly);
        buttonGroup1.add(jRadioButtonBacomSaic);
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    private class SwingAISAIC extends SwingWorker<Void, String>{

        protected Void doInBackground() throws Exception{

            //Bacom analysis
            ConfigObject myConfigObj = new ConfigObject();
            myConfigObj.readConfig("settings.xml");
            AnnotationDataSet annot = new AnnotationDataSet(myConfigObj.getAnnotationFile());
            Controller myCore = new Controller(myConfigObj, annot);
            myCore.run(true);

            //Convert BACOM results into SAIC inputS
            String bacomResultDir = "D:\\硕士论文\\代码\\我的整理\\BacomResult\\";
            String saicInputDir = "D:\\硕士论文\\代码\\我的整理\\SaicInput\\";
            DataConversion convertForSAIC = new DataConversion(myConfigObj,bacomResultDir,saicInputDir);
            try{
                convertForSAIC.transform();
            }
            catch(IOException e)
            {
                publish("Can not convert BACOM results to SAIC input because no BACOM results available." + "\n" + "\n");
                return null;
            }

            // Saic analysis
            DetectSCAs detectSCAs;
            ForkJoinPool detectSCAForkJoinPool;
            SaicParameters mySaicParam = new SaicParameters();
            String infiles[] = new String[1];
            String outfiles[] = new String[1];
            String tempInfile = "D:\\硕士论文\\代码\\我的整理\\SaicInput\\GenomeWide";
            String tempOutfile = "D:\\硕士论文\\代码\\我的整理\\SaicResults\\GenomeWide";
            infiles[0] = tempInfile;
            outfiles[0] = tempOutfile;
            detectSCAs = new DetectSCAs(mySaicParam, infiles, outfiles);
            detectSCAForkJoinPool = new ForkJoinPool();
            detectSCAForkJoinPool.invoke(detectSCAs);

            return null;
        }
    }

    private class SwingBacom extends SwingWorker<Void,String>{

        protected Void doInBackground() throws Exception{
            ConfigObject myConfigObj = new ConfigObject();
            myConfigObj.readConfig("settings.xml");
            AnnotationDataSet annot = new AnnotationDataSet(myConfigObj.getAnnotationFile());
            Controller myCore = new Controller(myConfigObj, annot);
            myCore.run(true);
            return null;
        }
    }

    private class SwingSCAs extends SwingWorker<Void, String>{

        DetectSCAs detectSCAs;
        ForkJoinPool detectSCAForkJoinPool;

        protected Void doInBackground(){

            SaicParameters mySaicParam = new SaicParameters();
            String infiles[] = new String[1];
            String outfiles[] = new String[1];
            String tempInfile = "D:\\硕士论文\\代码\\我的整理\\SaicInput\\GenomeWide";
            String tempOutfile = "D:\\硕士论文\\代码\\我的整理\\SaicResults\\GenomeWide";
            infiles[0] = tempInfile;
            outfiles[0] = tempOutfile;
            detectSCAs = new DetectSCAs(mySaicParam, infiles, outfiles);
            detectSCAForkJoinPool = new ForkJoinPool();
            detectSCAForkJoinPool.invoke(detectSCAs);

            return null;
        }
    }

    public static void main(String args[]){
        AisaicGui myAisaic = new AisaicGui();
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JMenuBar menuBar1;
    private JMenu menu1;
    private JMenuItem jMenuItemExit;
    private JPanel panel1;
    private JLabel label1;
    private JTextField jTextFieldAnnotFilePath;
    private JButton jButtonChooseAnnotFile;
    private JLabel label2;
    private JTextField jTextFieldCdfFilePath;
    private JButton jButtonChooseCdfFile;
    private JLabel label3;
    private JTextField jTextFieldBacomResultFolder;
    private JButton jButtonChooseBacomResultFolder;
    private JLabel label4;
    private JTextField jTextFieldNSample;
    private JButton jButtonChooseNSample;
    private JLabel label5;
    private JTextField jTextFieldTSample;
    private JButton jButtonChooseTSample;
    private JLabel label6;
    private JComboBox<String> comboBox1;
    private JButton jButtonParamSetting;
    private JButton button7;
    private JPanel panel2;
    private JLabel label7;
    private JTextField jTextFieldSaicInputFile;
    private JButton jButtonChooseSaicInputFile;
    private JLabel label8;
    private JTextField jTextFieldSaicResultFolder;
    private JButton jButtonChooseSaicResultFolder;
    private JLabel label9;
    private JTextField jTextFieldGeneFile;
    private JButton jButtonChooseGeneFile;
    private JButton button10;
    private JButton button11;
    private JPanel panel3;
    private JTextArea jTextAreaStatus;
    private JPanel panel4;
    private JToolBar toolBar2;
    private JButton jButtonStart;
    private JButton jButtonStop;
    private JButton button15;
    private JPanel panel5;
    private JRadioButton jRadioButtonBacomOnly;
    private JRadioButton jRadioButtonSaicOnly;
    private JRadioButton jRadioButtonBacomSaic;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
